<template>
    <div class="main">
        <!-- 个人信息 -->
        <div class="person-msg">
            <div class="touxiang">
                <img src="../../assets/touxiang.jpg" alt="">
                <span class="nicheng">昵称</span>
            </div>
            <div class="person-info">
                <div class="info-title">
                    <div class="title-head">
                        <trace theme="outline" size="22" fill="#333" :strokeWidth="3" strokeLinejoin="bevel" strokeLinecap="butt"/> <span>目标</span>
                    </div>
                    <div class="title-text">
                        前端工程师
                    </div>
                </div>
                <div class="info-body">
                    <div class="body-head">
                        <list-view theme="outline" size="22" fill="#333" :strokeWidth="3" strokeLinejoin="bevel" strokeLinecap="butt"/>
                        <span>技能</span>
                    </div>
                    <div class="body-text">
                        <div class="jindutiao">
                            css<el-progress :percentage="data1" :status="data1_status"></el-progress></div>
                        <div class="jindutiao">
                            JavaScript<el-progress :percentage="data2" :status="data2_status"></el-progress></div>
                        <div class="jindutiao">
                            JQuery<el-progress :percentage="data3" :status="data3_status"></el-progress></div>
                            <div class="jindutiao">
                                JQuery<el-progress :percentage="data3" :status="data3_status"></el-progress></div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 用户学习情况 -->
        <div class="study">
            <!-- 学习时长 -->
            <div class="study-time">
                <div class="time-left">
                    <div class="time-title">学习时长</div>
                    <div class="time-days">
                        <div class="tianshu">
                            <div class="tianshu-num">
                                <i></i>
                                <i></i>
                                <span>0</span>
                            </div>
                            <div class="tianshu-text">累计学习(天)</div>
                        </div>
                        <div class="shichang">
                            <div class="shichang-num">0</div>
                            <div class="shichang-text">学习时长(时)</div>
                        </div>
                    </div>
                </div>
                <div class="time-right">
                    <div ref="timeChart" id="time-chart" class="time-chart"></div>
                </div>
            </div>
            <div class="study-main">
                <div class="tabs">
                    <div class="tab-2">
                        <label for="tab2-1">One</label>
                        <input id="tab2-1" name="tabs-two" type="radio" checked="checked">
                    <div>
                        <h4>Tab One</h4>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas consequat id velit quis vestibulum. Nam id orci eu urna mollis porttitor. Nunc nisi ante, gravida at velit eu, aliquet sodales dui. Sed laoreet condimentum nisi a egestas. <a class="documentation" href="https://flkt.mx/pitaya/componentes.html#pestanias">Documentación en español</a>.</p><p>Donec interdum ante ut enim consequat, quis varius nulla dapibus. Vivamus mollis fermentum augue a varius. Vestibulum in sapien at lectus gravida lobortis vulputate sed metus. Duis scelerisque justo et maximus efficitur. Donec eu eleifend quam. Curabitur aliquet commodo sapien eget vestibulum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vestibulum vel aliquet nunc, finibus posuere lorem. Suspendisse consectetur volutpat est ut ornare.</p>
                    </div>
                    </div>
                    <div class="tab-2">
                        <label for="tab2-2">Two</label>
                        <input id="tab2-2" name="tabs-two" type="radio">
                        <div>
                        <h4>Tab Two</h4>
                        <p>Quisque sit amet turpis leo. Maecenas sed dolor mi. Pellentesque varius elit in neque ornare commodo ac non tellus. Mauris id iaculis quam. Donec eu felis quam. Morbi tristique lorem eget iaculis consectetur. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aenean at tellus eget risus tempus ultrices. Nam condimentum nisi enim, scelerisque faucibus lectus sodales at.</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import {Trace,ListView} from '@icon-park/vue';
import * as echarts from 'echarts'
export default {
    data(){
        return{
            data1:59,
            data2:39,
            data3:100,
            // status状态只能是‘success‘,'expection','warning'之一 或null 不能设置为''
            data1_status:null,
            data2_status:null,
            data3_status:'success',
            // 图表数据区域
            data : [],
            // 用户注册时间
            now : new Date(2022, 1, 1),
            oneDay : 24 * 3600 * 1000,
            value : Math.random() * 1000,
            timer:null //定时器
        }
    },
    components:{
        Trace,ListView
    },
    methods:{
        randomData() {
            this.now = new Date(+this.now + this.oneDay);
            this.value = this.value + Math.random() * 21 - 10;
            return {
                name: this.now.toString(),
                value: [
                [this.now.getFullYear(), this.now.getMonth() + 1, this.now.getDate()].join('/'),
                Math.round(this.value)
                ]
            };
        },
        // 图表数据初始化部分
        initChartData(){
            // var date = this.randomData()
            // console.log(this.randomData());
            // this.data.push(this.randomData())
            // console.log(this.data);
            for (var i = 0; i < 1000; i++) {
                // 给图表添加数据 {name: "Sun Jan 29 2023 00:00:00 GMT+0800 (中国标准时间)",value: ["2023/1/29", 617]}
                this.data.push(this.randomData());
            }
            // console.log(this.data);
        },
        drawLineChart(){
            // 初始化图表数据
            this.initChartData()
            // 获取元素并创建图表实例
            let timeChart = this.$echarts.init(this.$refs.timeChart)
            let params = this.data
            // 绘制图表
            timeChart.setOption({
                tooltip: {
                    trigger: 'axis',
                    formatter: function (params) {
                        params = params[0];
                        var date = new Date(params.name);
                        return (
                            date.getDate() +
                            '/' +
                            (date.getMonth() + 1) +
                            '/' +
                            date.getFullYear() +
                            ' : ' +
                            params.value[1]
                        );
                    },
                    axisPointer: {
                        animation: false
                    }
                },
                xAxis: {
                    type: 'time',
                    splitLine: {
                    show: false
                    }
                },
                yAxis: {
                    type: 'value',
                    boundaryGap: [0, '100%'],
                    splitLine: {
                        show: false
                    },
                    axisLabel: {
                        formatter: '{value} min'
                    }
                },
                series: [
                    {
                        name: 'Fake Data',
                        type: 'line',
                        showSymbol: false,
                        data: this.data
                    }
                ]
            })
            this.start(timeChart)
        },
        // getData(box){
        //     let date = [150, 230, 224, 218, 135, 147, 260]
        //     box.setOption({
        //         series: [
        //             {
        //             data: date,
        //             type: 'line'
        //             }
        //         ]
        //     })

        // },
        // 获取数据 开始使用定时器更新图表展示数据
        start(myChart){
            this.timer = setInterval(()=> {
                for (var i = 0; i < 5; i++) {
                    this.data.shift();
                    var date = this.randomData()
                    this.data.push(date);
                }
                myChart.setOption({
                    series: [
                    {
                        data: this.data
                    }
                    ]
                });
            }, 1000)
        },
        // 清除定时器
        end(){
            clearInterval(this.timer)
            this.timer = null
        }

    },
    mounted(){
        this.drawLineChart()
      this.$nextTick(() => {
        this.init();
      });
    }
}
</script>
<style>

.main{
    margin: 0;
    padding: 20px 20px;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    display: flex;
    background-color: #ebeff5;
}
.person-msg{
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 450px;
    height: 600px;
    background-color: #fff;
}
.touxiang{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 200px;
}
.touxiang img{
    width: 100px;
    height: 100px;
    border-radius: 50px;
}
.nicheng{
    font-size: 20px;
    margin-top: 10px;
}
.person-info{
    box-sizing: border-box;
    width: 100%;
    padding: 20px 15px;
}
.info-title{
    height: 80px;
    width: 100%;
}
.title-head,.body-head{
    display: flex;
    justify-content: flex-start;
    align-items: center;
    height: 45px;
    width: 100%;
    border-bottom: 1px solid #ccc;
}
.title-head span:nth-child(2),
.body-head span:nth-child(2){
    margin-left: 5px;
    font-size: 16px;
    font-weight: 800;
}
.title-text{
    height: 35px;
    line-height: 35px;
    color: #958e97;
}
.info-body{
    width: 100%;
    margin-top: 20px;
}
.body-head{
    height: 45px;
    border-bottom: 1px solid #ccc;
}
.body-text{
    padding: 10px;
}
.jindutiao{
    margin-top: 10px;
}
.study{
    width: 1300px;
    margin-left: 30px;
    background-color: #ebeff5;
}
.study-time{
    display: flex;
    height: 220px;
    padding: 20px;
    background-color: #fff;
}
.time-left{
    width: 382px;
    padding-left: 20px;
}
.time-title{
    font-size: 25px;
}
.time-days{
    display: flex;
    margin-top: 38px;
    height:116px;
    width: 250px;
}
.tianshu{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    height: 116px;
    width: 125px;
    padding-left: 10px;
}
.tianshu-num{
    width: 45px;
    height: 80px;
}
.tianshu-num{
    position: relative;
}
.tianshu-num i{
    display: block;
    margin: 0;
    padding: 0;
    width: 45px;
    height: 35px;
    border: 2px solid #958e97;
    border-radius: 5px;
    background-color: #f5f2e9;
}
.tianshu-num span{
    position: absolute;
    top: 0;
    left: 7px;
    font-size: 56px;
    font-weight: 600;
    color: #5f479a;
}
.tianshu-text{
    margin-top: 10px;
}
.shichang{
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-sizing: border-box;
    width: 125px;
    height: 116px;
}
.shichang-num{
    height: 80px;
    line-height: 122px;
    font-size: 35px;
    font-weight: 600;
    color: #5f479a;
}
.shichang-text{
    margin-top: 10px;
}
.time-right{
    position: relative;
    width: 760px;
    height: 220px;
    background-color: #f6f3fe;
}
.time-chart{
    position: absolute;
    top: -40px;
    left: 20px;
    width: 760px;
    height: 300px;
}

.study-main{
    box-sizing: border-box;
    width: 100%;
    height: 500px;
    margin-top: 20px;
    padding: 20px;
    background-color: #fff;
}

.tabs {
    background: #fff;
    color: #000;
    font-family: "Roboto", Arial, Helvetica, sans-serif;
    font-size: 16px;
    font-weight: 300;
    letter-spacing: 0.01em;
    line-height: 1.6em;
    margin: 0;
}
h1 {
    font-size: 40px;
    line-height: 0.8em;
    color: rgba(255,255,255,0.2);}
.made-with {
    background: #fd264f;
    color: #fff;
    display: block;
    font-size: 12px;
    line-height: 1em;
    margin: 0;
    padding: 5px 110px;
    position: fixed;
    top: 20px;
    right: -100px;
    text-align: center;
    text-decoration: none;
    transform: rotate(45deg);
}
.documentation {
    color: #fd264f;
}
button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: none;
}

.tabs {
    display: block;
    display: -webkit-flex;
    display: -moz-flex;
    display: flex;
    -webkit-flex-wrap: wrap;
    -moz-flex-wrap: wrap;
    flex-wrap: wrap;
    margin: 0;
    overflow: hidden;
}
.tabs [class^="tab"] label,
.tabs [class*=" tab"] label {
    cursor: pointer;
    display: block;
    font-size: 1.1em;
    font-weight: 300;
    line-height: 1em;
    padding: 2rem 0;
    text-align: center; }
.tabs [class^="tab"] [type="radio"],
.tabs [class*=" tab"] [type="radio"] {
    border-bottom: 1px solid rgba(239, 237, 239, 0.5);
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    display: block;
    width: 100%;
    -webkit-transition: all 0.3s ease-in-out;
    -moz-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
}
.tabs [class^="tab"] [type="radio"]:hover, .tabs [class^="tab"] [type="radio"]:focus,
.tabs [class*=" tab"] [type="radio"]:hover,
.tabs [class*=" tab"] [type="radio"]:focus {
    border-bottom: 1px solid #fd264f;
}
.tabs [class^="tab"] [type="radio"]:checked,
.tabs [class*=" tab"] [type="radio"]:checked {
    border-bottom: 2px solid #fd264f;
}
.tabs [class^="tab"] [type="radio"]:checked + div,
.tabs [class*=" tab"] [type="radio"]:checked + div {
    opacity: 1;
}
.tabs [class^="tab"] [type="radio"] + div,
.tabs [class*=" tab"] [type="radio"] + div {
    display: block;
    opacity: 0;
    padding: 2rem 0;
    width: 90%;
    -webkit-transition: all 0.3s ease-in-out;
    -moz-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
}
.tabs .tab-2 {
    box-sizing: border-box;
    width: 50%;
    padding: 0 20px;
}
.tabs .tab-2 [type="radio"] + div {
    width: 200%;
    margin-left: 200%;
}
.tabs .tab-2 [type="radio"]:checked + div {
    margin-left: 0;
}
.tabs .tab-2:last-child [type="radio"] + div {
    margin-left: 100%;
}
.tabs .tab-2:last-child [type="radio"]:checked + div {
    margin-left: -100%;
}
</style>
